<?php

	// TITLE: Organization_phone AUTO MODEL
	// FILE: scaffolding/model/organization_phone.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createOrganizationPhone = function($con, $organizationPhone) {
		$sql = 'INSERT INTO organization_phone (organization_id, phone_id) VALUES (';
		$sql .= $organization_phone->getOrganizationId() . ', ';
		$sql .= $organization_phone->getPhoneId() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readOrganizationPhone = function($con, $id) {
		$sql = 'SELECT * FROM organization_phone WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$organizationPhone = new OrganizationPhone();
			$organizationPhone->setOrganizationId($dbio->select($readOrganization(result[0])));
			$organizationPhone->setPhoneId($dbio->select($readPhone(result[1])));
		} else {
			$organizationPhone = false;
		}
		return $organizationPhone;
	};

	$updateOrganizationPhone = function($con, $organizationPhone) {
		$sql = 'UPDATE organization_phone SET ';
		$sql .= 'organization_id = ' . $organization_phone->getOrganizationId() . ', ';
		$sql .= 'phone_id = ' . $organization_phone->getPhoneId() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteOrganizationPhone = function($con, $id) {
		$sql = 'DELETE FROM organization_phone WHERE organization_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listOrganizationPhone = function($con) {
		$sql = 'SELECT * FROM organization_phone';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$organizationPhones = array();
			while ($result = mysqli_fetch_array($results)) {
				$organizationPhone = new OrganizationPhone();
				$organizationPhone->setOrganizationId($dbio->select($readOrganization(result[0])));
				$organizationPhone->setPhoneId($dbio->select($readPhone(result[1])));
				$organizationPhones[] = organizationPhone;
			}// end while
		} else {
			$organizationPhones = false;
		}
		return $organizationPhones;
	};

